﻿#ifndef JOBJECTOBSERVER_P_H
#define JOBJECTOBSERVER_P_H

#include "jobjectobserver.h"
#include <QList>

#define J_IMPLEMENT_OBSERVER(_class_) \
    void _class_::setObserver(_class_ ## Observer *add, _class_ ## Observer *remove) { \
        J_D(_class_); \
        if (add && d->_observers.contains(add) == false) { \
            d->_observers.push_back(add); \
        } \
        if (remove) { \
            d->_observers.removeOne(remove); \
        } \
    }

#define J_DECLARE_OBSERVER_PRIVATE(_class_) \
    QList<_class_ ## Observer *> _observers;



#define J_EMIT_OBSERVER_PRIVATE(_class_, _method_params_) \
    do { \
        QListIterator<_class_ ## Observer *> iter(_observers); \
        while (iter.hasNext()) { \
            iter.next()->_method_params_; \
        } \
    } while (0);

#endif // JOBJECTOBSERVER_P_H
